﻿using Coldairarrow.Util.Excel.Util;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Coldairarrow.Util.Excel.Analyze
{
    public class ExcelDataAnalyzer : BaseDataAnalyzer
    {
        private IWorkbook workbook = null;

        public ExcelDataAnalyzer(IWorkbook workbook)
        {
            this.workbook = workbook;
        }

        public DataSet Analyze(ParseExcelRuleUtil parseExcelRuleUtil)
        {
            if (this.workbook == null)
            {
                throw new Exception("缺少Excel工作簿!");
            }
            else
            {
                return base.GetAnalyzeDataSet(parseExcelRuleUtil, this.workbook);
            }
        }


        

        internal List<List<string>> Analyze(string sheetName, int startRow, int endRow)
        {
            if (this.workbook == null)
            {
                throw new Exception("缺少Excel工作簿!");
            }
            else
            {
                ISheet sheet = this.workbook.GetSheet(sheetName);
                if (sheet == null)
                {
                    throw new Exception("传入的sheet页名称[" + sheetName + "]在文件中不存在");
                }
                else
                {
                    return base.GetSheetContent(sheet, startRow, endRow);
                }
            }
        }
    }
}
